package fdq.servlet;

import com.alibaba.fastjson.JSON;
import fdq.entity.Feature;
import fdq.service.MainService;
import fdq.service.MainServiceImp;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;



@WebServlet("/getAllFeatures")
public class IndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("utf-8");
        resp.setHeader("Access-Control-Allow-Origin", "*");

        MainService mainService = new MainServiceImp();
        Feature[] allFeatures = mainService.selectAllFeatures();

        //发送给前端
        Map<String,Object> map=new HashMap<>();
        map.put("allFeatures",allFeatures);
        String json= JSON.toJSONString(map);
        PrintWriter pw =resp.getWriter();
        pw.print(json);
    }
}
